package com.ruoyi.sync;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.interfaceConfig.sceneConfig.service.ISceneConfigService;
import com.ruoyi.syncCore.SyncCoreTemplate;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Yuan
 * @description
 * @date 2024/3/23
 */
@Component
public abstract class BaseService {
    @Autowired
    private ISceneConfigService sceneConfigService;
    @Autowired
    private SyncCoreTemplate syncCoreTemplate;

    public AjaxResult syncData(String tableName) {
        //获取客户的场景信息
        List<Long> sceneConfigIds = sceneConfigService.getSceneConfigIds(tableName);
        if(sceneConfigIds == null || sceneConfigIds.size() == 0) {
            return AjaxResult.error("未配置同步场景");
        }
        //同步数据
        syncCoreTemplate.syncDataForDown(sceneConfigIds.get(0));
        return AjaxResult.success();
    }
}
